#!/bin/bash

echo "start  pack: "

var_pack_list=""
var_common_path="./app/common/"
var_luac_path="./skynet/3rd/lua/luac"

var_pwd=`pwd`
echo "Current Path:"$var_pwd
var_pro_tmp=`dirname $var_pwd`
trunk_dir=`basename $var_pwd`

var_tmp_path="./nhserver"


if [ ! -d $var_tmp_path ]; then
  `mkdir $var_tmp_path`
fi

echo "Trunk:"$trunk_dir
var_tmp_trunk=$var_tmp_path"/"$trunk_dir
if [ ! -d $var_tmp_trunk ]; then
  `mkdir -p $var_tmp_trunk`
fi

echo "copy $trunk_dir ....."
`rm -rf applog`
`cp -r * $var_tmp_trunk`
echo "compile lua-script............"
Luas=`find ${var_tmp_path} -name *.lua`
for line in ${Luas};
do
    `$var_luac_path -o $line $line`
    echo "compile lua file: "$line"......"
done
`rm -rf $var_tmp_trunk/skynet`
`rm -rf $var_tmp_trunk/tmp`
        

var_dir="../package"
if [ ! -d $var_dir ]; then
  `mkdir $var_dir`
fi

svndir=`find ./ -name .svn`
`rm -rf $svndir`
gitdir=`find ./ -name .git`
`rm -rf $gitdir`
echo "================="
echo "begin pack"
var_file="${var_dir}/${project_dir}_${trunk_dir}_$(date '+%Y%m%d%H%M%S').zip"
des_dir="${var_tmp_path}/${project_dir}"
zip -r ${var_file} ${des_dir}

cd ${var_pwd}
`rm -rf $var_tmp_path`
